package com.jss.lanouhn.fristapp.adapters;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.jss.lanouhn.fristapp.R;
import com.jss.lanouhn.fristapp.activity.HomeItemDetail;
import com.jss.lanouhn.fristapp.modles.SelecterSampleImgInfo;
import com.squareup.picasso.Picasso;

/**
 * Created by lanouhn on 16/9/5.
 */
public class RV_RecommendAdapter extends RecyclerView.Adapter<RV_RecommendAdapter.RecommendViewHolder>{
    private SelecterSampleImgInfo selecterSampleImgInfo;
    private Context context;

    public RV_RecommendAdapter(SelecterSampleImgInfo selecterSampleImgInfo, Context context) {
        this.selecterSampleImgInfo = selecterSampleImgInfo;
        this.context = context;
    }



    @Override
    public RecommendViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(context).inflate(R.layout.item_rv_recommend,null);
        RecommendViewHolder holder=new RecommendViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecommendViewHolder holder, int position) {

        final SelecterSampleImgInfo.DataBean.RecommendPostsBean bean=
                selecterSampleImgInfo.getData().getRecommend_posts().get(position);
        Picasso.with(context).load(bean.getCover_image_url()).into(holder.iv);
        holder.tv.setText(bean.getTitle());

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context, HomeItemDetail.class);
                intent.putExtra("id",""+bean.getId());
                context.startActivity(intent);
            }
        });



    }

    @Override
    public int getItemCount() {
        return selecterSampleImgInfo.getData().getRecommend_posts().size();
    }

    public class RecommendViewHolder extends RecyclerView.ViewHolder{
        private ImageView iv;
        private TextView tv;

        public RecommendViewHolder(View itemView) {
            super(itemView);
            iv= (ImageView) itemView.findViewById(R.id.iv_sample_recommend);
            tv= (TextView) itemView.findViewById(R.id.tv_sample_recommend);


        }

    }
}
